﻿
/*
 * PsTFS is a set of PowerShell commands to manage and use Team Foundation Server. PowerShell 
 * effectiveness is combined with the power of TFS API to maximizes TFS capabilities.
 * 
 * Creator : Choulant Noham
 * Mail : choulant@gmail.com
 * Blog : http://choulant.blogspot.com
 * 
 */

using System;
using System.Management.Automation;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
using PsTFS.Methodes;
using PsTFS.Objects;

namespace PsTFS.Commandes.Add
{
    /// <summary>
    /// Permet de créer un nom projet Team Foundation Server
    /// </summary>
    [Cmdlet(VerbsCommon.Add, "Project")]
    public class Add_Project : PsCmdlet
    {
        /// <summary>
        /// Lancement du processus de création du projet
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                ICommonStructureService css = Methode_Service.ICSS();
                Methode.CreateProject(Context.Instance.Tfs.Name, this.LogFolder, this.ProjectName, this.ProjectSiteTitle, this.ProjectSiteDescription, this.SccCreateType, this.SccBranchFromPath, this.ProcessTemplateName);

            }
            catch (Exception ex)
            {
                ErrorRecord err = new ErrorRecord(ex, Error.GetInstance().GetError(this), ErrorCategory.WriteError, null);
                WriteError(err);
                Log.AddLog(ex.StackTrace);
            }
            finally
            {
                base.ProcessRecord();
            }

        }

        /// <summary>
        /// Permet d'informer la fin de la commande
        /// </summary>
        protected override void EndProcessing()
        {
            Log.AddLog(null, "Add-Project is end");
            base.EndProcessing();
        }

        /// <summary>
        /// Object contenant Team Foundation Server
        /// </summary>
        [Parameter(Position = 0)]
        public TfsTeamProjectCollection TFS
        {
            set
            {
                Context.Instance.Tfs = value;
            }
        }

        /// <summary>
        /// Nom du projet à créer
        /// </summary>
        [Parameter(Position = 1, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public string ProjectName { get; set; }

        /// <summary>
        /// Emplacement en local du fichier de log
        /// </summary>
        [Parameter(Position = 2, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public string LogFolder { get; set; }

        /// <summary>
        /// Nom du site projet
        /// </summary>
        [Parameter(Position = 3, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public string ProjectSiteTitle { get; set; }

        /// <summary>
        /// Description du site projet
        /// </summary>
        [Parameter(Position = 4, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public string ProjectSiteDescription { get; set; }

        /// <summary>
        /// Object contenant Team Foundation Server
        /// </summary>
        [Parameter(Position = 5, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public string SccCreateType { get; set; }

        /// <summary>
        /// Object contenant Team Foundation Server
        /// </summary>
        [Parameter(Position = 6)]
        [ValidateNotNullOrEmpty]
        public string SccBranchFromPath { get; set; }

        /// <summary>
        /// Object contenant Team Foundation Server
        /// </summary>
        [Parameter(Position = 7, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public string ProcessTemplateName { get; set; }

    }
}


